using System;
using System.Collections.Generic;
using System.Text;
using Fodee.DataEntity;
using System.Data.Common;
using Fodee.DataAccess;

namespace Fodee.BusinessComponent
{
    public class fodFoodBC : FodeeBCBase
    {
        public readonly fodFoodDA da = new fodFoodDA();
        public fodFoodBC()
        {
        }

        public bool Insert(FodeeDataSet ds)
        {
            try
            {

                using (DbTransaction dbTransaction = da.GetConnection().BeginTransaction())
                {
                    try
                    {
                        bool result = da.Insert(ds, dbTransaction);
                        if (result)
                        {
                            dbTransaction.Commit();
                        }
                        else
                        {
                            dbTransaction.Rollback();
                        }
                        return result;
                    }
                    catch (Exception ex)
                    {
                        dbTransaction.Rollback();
                        throw ex;
                    }
                }
            }
            catch (Exception ex)
            {
                //TODO:handle exception
                //TODO:log exception
                throw ex;
            }

        }

        public int Add(FodeeDataSet ds)
        {
            try
            {

                using (DbTransaction dbTransaction = da.GetConnection().BeginTransaction())
                {
                    try
                    {
                        int result = da.Add(ds, dbTransaction);
                        dbTransaction.Commit();
                        return result;
                    }
                    catch (Exception ex)
                    {
                        dbTransaction.Rollback();
                        throw ex;
                    }
                }
            }
            catch (Exception ex)
            {
                //TODO:handle exception
                //TODO:log exception
                throw ex;
            }

        }

        public bool Update(FodeeDataSet ds)
        {
            try
            {

                using (DbTransaction dbTransaction = da.GetConnection().BeginTransaction())
                {
                    try
                    {
                        bool result = da.Update(ds, dbTransaction);
                        if (result)
                        {
                            dbTransaction.Commit();
                        }
                        else
                        {
                            dbTransaction.Rollback();
                        }
                        return result;
                    }
                    catch (Exception ex)
                    {
                        dbTransaction.Rollback();
                        throw ex;
                    }
                }
            }
            catch (Exception ex)
            {
                //TODO:handle exception
                //TODO:log exception
                throw ex;
            }

        }

        public bool Delete(int id)
        {
            try
            {

                using (DbTransaction dbTransaction = da.GetConnection().BeginTransaction())
                {
                    try
                    {
                        bool result = da.Delete(id, dbTransaction);
                        if (result)
                        {
                            dbTransaction.Commit();
                        }
                        else
                        {
                            dbTransaction.Rollback();
                        }
                        return result;
                    }
                    catch (Exception ex)
                    {
                        dbTransaction.Rollback();
                        throw ex;
                    }
                }
            }
            catch (Exception ex)
            {
                //TODO:handle exception
                //TODO:log exception
                throw ex;
            }

        }

        public FodeeDataSet GetByID(int id)
        {
            try
            {

                return da.GetByID(id);
            }
            catch (Exception ex)
            {
                //TODO:handle exception
                //TODO:log exception
                throw ex;
            }

        }

        public FodeeDataSet GetAll()
        {
            try
            {

                return da.GetAll();
            }
            catch (Exception ex)
            {
                //TODO:handle exception
                //TODO:log exception
                throw ex;
            }

        }


    }
}


